/** * llmindex.io — GET /api/v1/models/:slug (full model profile; slug contains "/") * Author: Simon-Pierre Boucher * Contact: contact@spboucher.ai * License: Proprietary — © Simon-Pierre Boucher, all rights reserved */ import { type NextRequest } from 'next/server'; import { getModelProfile } from '@/lib/data'; import { apiError, apiJson } from '@/lib/api'; import { rateLimit } from '@/lib/rate-limit'; export const dynamic = 'force-dynamic'; export async function GET(req: NextRequest, { params }: { params: { slug: string[] } }) { const limited = await rateLimit(req); if (limited) return limited; const slug = params.slug.join('/'); const profile = await getModelProfile(slug); if (!profile) return apiError(404, 'model_not_found_or_not_scored'); return apiJson( { index_version: profile.run.indexVersion, model: { slug: profile.slug, name: profile.name, provider: profile.provider, context_length: profile.contextLength, prompt_price_per_1m_usd: profile.promptPricePerM, completion_price_per_1m_usd: profile.completionPricePerM, }, run: { id: profile.run.id, kind: profile.run.kind, status: profile.run.status, created_at: profile.run.createdAt, notes: profile.run.notes, }, global: profile.global ? { score: profile.global.score, score_low: profile.global.scoreLow, score_high: profile.global.scoreHigh, } : null, domains: profile.domains.map((d) => ({ domain: d.domain, score: d.score, score_low: d.scoreLow, score_high: d.scoreHigh, sub_metrics: d.subMetrics, })), run_history: profile.runHistory.map((h) => ({ run_id: h.runId, index_version: h.indexVersion, kind: h.kind, created_at: h.createdAt, score: h.score, })), }, { cacheSeconds: 3600 }, ); }